﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;

public partial class gold_eGoldSearch : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bd(1);
        }
    }

    private void bd(int page)
    {

        CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();

        string strCol = GetRequest("col");
        string strKey = GetRequest("key");
        strKey = Server.UrlDecode(strKey);
        string strDate1 = GetRequest("date1");
        string strDate2 = GetRequest("date2");
        DateTime date1, date2;
        if (strDate1 == "")
        {
            date1 = Convert.ToDateTime("2011-01-01");
        }
        else
            date1 = Convert.ToDateTime(strDate1);
        if (strDate2 == "")
        {
            date2 = Convert.ToDateTime("2021-01-01");
        }
        else
            date2 = Convert.ToDateTime(strDate2);

        var list = dal.eGold_Info.Where(x => x.colname == strCol && x.key.Contains(strKey) && x.date >= date1 && x.date <= date2);

        AspNetPager1.RecordCount = list.Count();
        AspNetPager1.CurrentPageIndex = page;
        list = list.OrderByDescending(x => x.date).Skip((page - 1) * AspNetPager1.PageSize).Take(AspNetPager1.PageSize);

        Repeater1.DataSource = list;
        Repeater1.DataBind();
    
    }

    public int GetPage()
    {
        return AspNetPager1.CurrentPageIndex;
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        bd(AspNetPager1.CurrentPageIndex);
    }

    public string GetRequest(string name)
    {
        string strReturn = "";
        if (Request[name] != null)
        {
            strReturn = Request[name].ToString();
        }
        return strReturn;
    }


}